const edit = {
  props:{
    
  },
  data(){
    return {
      isShow: false,
      title: null,
      btnLoading: false,
      params: null,
      form:{

      },
      indTypes:[],
      indLabel: null,
      initData:{},
    }
  },
  methods:{
    init(params){
      this.isShow = true;
      this.params = JSON.parse(JSON.stringify(params));
      this.form = JSON.parse(JSON.stringify(params));
      console.log(this.form);
      if(this.form.update_time){
        this.form.update_time = this.$moment(this.form.update_time).format('YYYY-MM-DD HH:mm:ss')
      }
      this.title = params.name;
      this.initData = JSON.parse(JSON.stringify(this.$parent.$parent.initData));
      this.initData.countys.shift();  
      this.initCallback();    
    },
    initCallback(){

    },
    changeEmissions(val, type){
      if(val){
        this.form[type] = Number(val).toFixed(2);
      }      
    },
    closeDrawer(){
      this.form = {};
      this.indTypes = [];
      this.indLabel = null;
      this.$emit('close')
    },
    verifyForm(){
      if(!this.$verify.null(this.form.name, '请填写污染源名称')){
        return false;
      }
      //经度[113-115]
      if(Number(this.form.lon) < 113 || Number(this.form.lon) > 115){
        this.$message.warning('经度须在113-115之间')
        return false;
      }
      //纬度[21-23]
      if(Number(this.form.lat) < 21 || Number(this.form.lat) > 23){
        this.$message.warning('纬度须在21-23之间')
        return false;
      }
      if(!this.$verify.null(this.form.county, '请选择所属区县')){
        return false;
      }
      return true;
    },
    submitForm(){
      if(!this.verifyForm()){
        return;
      }
      if(JSON.stringify(this.params) == JSON.stringify(this.form)){
        this.isShow = false;
        return;
      }else{
        this.form.update_time = this.$moment().format('YYYY-MM-DD HH:mm:ss');
        this.form.last_editor = this.$store.getters.currentUser;
      }
      this.btnLoading = true;
      this.$request('post', '/stations/ind', this.form, (data,msg) => {
        if(data.msg == '更新成功'){
          this.$message.success(data.msg);
          this.btnLoading = false;        
          this.isShow = false;
          this.$emit('save');
        }else{
          this.$message.error(data.msg);
          this.btnLoading = false;
        }
      },msg => {
        this.btnLoading = false;
      })

    },
  }
}

export default edit;